'use strict';
module.exports = async ({collection, dbCmd, params, token, uniID}) => {
	let res = {}
	let payload = await uniID.checkToken(token)
	if(params){
		params = JSON.parse(params)
	}
	if (payload.code == 0) {
			let total = (await collection.where({_id: dbCmd.exists(true)}).count()).total
		if(params) {
			let pageSize = Number(params.pageSize)
			let pageNumber = Number((Number(params.pageNumber)-1) * pageSize)
			res = await collection.where({  
					typeName:params.typeName?new RegExp(`^${params.typeName}`, 'i'):dbCmd.exists(true)
				})
				.skip(pageNumber)
				.limit(pageSize)
				.get()
		}else{
			res = await collection.get()
		}
		res = {...res,total,code:0,msg:'查询成功'}
	} else {
		res = payload
	}
	//返回数据给客户端 
	return res
}
